<?php

namespace YmPhp\Admin\Http\Forms;

use YmPhp\Admin\Admin;
use YmPhp\Admin\Models\Setting as SystemSettingModel;
use YmPhp\Admin\Widgets\Form;

class MemberLevelForm extends Form
{
    /**
     * The form title.
     *
     * @var string
     */
    public $title = '基本设置';

    /**
     * Handle the form request.
     *
     * @param Request $request
     *
     */
    public function handle(array $input)
    {
        (new SystemSettingModel())->saveConfig($input,'member_vip');
        return $this->response()->success('保存成功')->refresh();
    }

    /**
     * Build a form here.
     */
    public function form()
    {


        Admin::style("
            .text-capitalize {
                text-align: right;
            }
            .table td, .table th {
                border-top: 0px solid #eff1f7;
            }
            .table thead th {
                text-align: center;
            }
            .vs-checkbox-primary {
                padding-top: 5px;
            }
        ");
        $this->tab(trans('setting.basic.basic_settings'), function () {
            $this->text('title', '卡名')->width(4);
            $this->radio('is_cdkey','是否可以用激活码')->options([1=>'开启',0=>'关闭']);
            $this->radio('is_activity_review','发布活动审核')->options([1=>'开启',0=>'关闭']);
            $this->checkbox('service_scope','服务范围')->options(['需要预约', '无需预约', '茶水免费', '谢绝自带酒水', '提供wifi']);
            $this->number('code_validity', '激活码有效期');
            $this->radio('open_inview','附近优惠推荐')->options([1=>'是',0=>'否']);
            $this->text('card_bottom_tip','卡底文字')->width(4);
            $this->text('card_title','开卡页面标题')->width(4);
            $this->textarea('card_desc','开卡页面描述')->width(4);
        });
        $this->tab('特权管理', function () {
            $this->table('card_type','卡片规格', function ($table) {
                $table->text('name','卡名');
                $table->text('validity','有效期');
                $table->text('price','价格');
                $table->text('original_price','原价');
                $table->text('desc','描述');
                $table->text('app_price','app内开卡价格');
            })->saving(function ($v) {
                return json_encode($v);
            })->width(10,2);
            $this->number('pub_activity_img_max_num','发布活动最大图片数');
            $this->radio('home_default_sort','首页默认排序')->options([
                'auto'      => '智能排序',
                'nearby'    => '附近优先',
                'sellnum'   => '领取最多',
                'views'     => '人气最高'
            ]);
            $this->number('experience_max_num','体验卡最大购买次数');
            $this->number('auto_repair_stock','每天自动补库存');
            $this->number('free_release_info','黑卡免费发信息（天）');
            $this->radio('is_join_business','使用激活码入驻商家')->options([1=>'开启',0=>'关闭']);
            $this->radio('is_offline_payment','黑卡消费线下支付')->options([1=>'开启',0=>'关闭']);
            $this->radio('is_trading_area','使用商圈筛选')->options([1=>'开启',0=>'关闭']);
            $this->number('release_info_discount','发布信息折扣');
            $this->number('join_in_business_discount','入驻商家折扣');
            $this->number('top_info_discount','置顶信息折扣');
            $this->radio('free_contact_information','免费查看联系方式')->options([1=>'开启',0=>'关闭']);
            $this->number('fictitious_card_num','虚拟开卡数');
            $this->radio('is_home_dynamic','开启首页动态')->options([1=>'开启',0=>'关闭']);
            $this->checkbox('rich_home_type','丰富首页商品类型')->options([
                1 => '不显示商品类型',
                2 => '同城优惠券',
                3 => '同城抢购',
                4 => '同城活动',
                5 => '商城商品',
                6 =>'拼团商品'
            ]);
        });
        $this->tab(__('admin.share'), function () {
            $this->text('share_title', __('admin.share_title'));
            $this->textarea('share_desc', __('admin.share_desc'));
            $this->image('share_pic', __('admin.share_pic'))->move('upload/share/pic/')->autoUpload()->uniqueName()->saveFullUrl();

        });

    }

    /**
     * The data of the form.
     *
     * @return array $data
     */
    public function data()
    {
        $datas = SystemSettingModel::pluck('value', 'key');
        return $datas['member_vip'];
    }


    }
